import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'normalize.css'
import 'nprogress/nprogress.css'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

//富文本编辑器
import VueQuillEditor from 'vue-quill-editor'

// import * as filters from '@/filters'

import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor);

// 全局样式
import '@/assets/css/index.css'

//时间格式化
import moment from 'moment'

//定时日期过滤器
Vue.filter('date', function(n) {

  const result = moment(n * 1000).format('YYYY年MM月DD日 hh时mm分ss秒')

  return result;
})

// 全局api
import * as API from '@/http/api'

console.log('API', API)

Vue.prototype.$API = API

// 面包屑
import crumbs from './components/Crumbs/Crumbs.vue'
Vue.component('crumbs',crumbs)

//路由守卫设置
router.beforeEach((to, from, next) => {

  // console.log('to::', to)
  const flag = to.matched.some(item => {
      return item.meta.auth
  })

  //如果flag为true,需要鉴权
  if (flag) {
      //获取token
      const token = sessionStorage.getItem('token')

      //如果没有token,直接回到登录页
      if (!token) {
          return next({ path: '/' })
      }

      //如果有token，直接放行
      next()
  } else {
      //不需要鉴权也放行
      next()
  }

})

Vue.config.productionTip = false



new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
